package com.pjh.shitang.controller;

import com.pjh.shitang.services.CommentService;
import com.pjh.shitang.utils.vo.receive.LikeInfo;
import com.pjh.shitang.utils.vo.receive.PageInfo;
import com.pjh.shitang.utils.vo.receive.PublishInfo;
import com.pjh.shitang.utils.vo.returns.DataWithLike;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yueyinghaibao
 * @date 2022/5/1
 */
@Api(value = "评论相关接口", tags = "评论管理")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    CommentService commentService;

    @ApiOperation("发布评论")
    @PostMapping("/publish")
    public Boolean publish(@RequestBody PublishInfo info) {
        return commentService.save(info);
    }

    @ApiOperation("点赞")
    @PostMapping("/like")
    public Boolean like(@RequestBody LikeInfo info) {
        return commentService.addLike(info);
    }

    @ApiOperation("取消点赞")
    @PostMapping("/dislike")
    public Boolean dislike(@RequestBody LikeInfo info) {
        return commentService.decLike(info);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public List<DataWithLike<Object>> page(@RequestBody PageInfo info) {
        return commentService.queryPage(info);
    }

}
